sap.ui.define(
  [
    "sap/ui/core/mvc/Controller",
    'sap/ui/core/Fragment',
    "sap/m/MenuItem",
    "sap/ui/model/json/JSONModel",
  ],
  function (BaseController, Fragment, MenuItem, JSONModel) {
    "use strict";

    return BaseController.extend("autofiror.controller.App", {
      onCollapseExpandPress: function () {
        var oSideNavigation = this.byId("sideNavigation");
        var bExpanded = oSideNavigation.getExpanded();

        oSideNavigation.setExpanded(!bExpanded);
      },

      onHideShowSubItemPress: function () {
        var oNavListItem = this.byId("subItem3");
        oNavListItem.setVisible(!oNavListItem.getVisible());
      },

      onItemSelect: function (oEvent) {
        var sKey = oEvent.getParameter("item").getKey();

        this.getOwnerComponent().getRouter().navTo(sKey);
      },

      onMenuIconPress: function () {
        var oView = this.getView(),
          oButton = oView.byId("menuIcon");

        if (!this._oMenuFragment) {
          this._oMenuFragment = this.loadFragment({
            id: oView.getId(),
            name: "autofiror.view.menu.Menu",
            controller: this
          }).then(function (oMenu) {
            oMenu.openBy(oButton);
            this._oMenuFragment = oMenu;
            return this._oMenuFragment;
          }.bind(this));
        } else {
          this._oMenuFragment.openBy(oButton);
        }
      },


      onInit: function () {
        if (this.getView().getModel("device").oData.system.phone) {
          this.getView().byId("desktopHeader").addStyleClass("none");
          this.getView().byId("phoneHeader").addStyleClass("full_width");
          this.getView().byId("phoneHeader").addStyleClass("sp_bt");
        }
        if (this.getView().getModel("device").oData.system.desktop) {
          this.getView().byId("phoneHeader").addStyleClass("none");
          this.getView().byId("desktopHeader").addStyleClass("full_width");
          this.getView().byId("desktopHeader").addStyleClass("cc");
        }
      }
    });
  }
);
